import {BaseEle} from "./core.js";
import {webkitLineClamp} from "./core_linecamp.js";

function isNativeSupport() {
    return typeof document.body.style.webkitLineClamp === 'undefined'
}

class ZTruncate extends BaseEle {
    constructor() {
        super();
        this._render();
        this._oldDisplay = ''
    }
    _render() {
        this._oldDisplay = this.style.display;
        this._log('truncate line', parseFloat(this._getAttr('line')))
        webkitLineClamp(this, parseFloat(this._getAttr('line')))
    }
    attrChanged(name, oldValue, newValue) {
        if (name === 'line') {
            this._render()
        }
    }
    clear() {
        if (isNativeSupport()) {
            this.style.display = this._oldDisplay
        }
        else {
            webkitLineClamp(this, 100000)
        }
    }
}

ZTruncate.defsel('z-truncate', {
    attrs: {
        line: '3',
    }
});